//
//  YSEmoticonCell.m
//  YSEmoticonKeyboard
//
//  Created by MOLBASE on 2017/12/22.
//  Copyright © 2017年 YangShen. All rights reserved.
//

#import "YSEmoticonCell.h"
#import "UIImage+YSAdd.h"
#import "YYImage.h"

#define kEmotionWH YSEmoticonScreenWidth * 0.0875

@interface YSEmoticonCell ()

@property (nonatomic, strong) UIImageView *iconImageView;

@end

@implementation YSEmoticonCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self initialize];
    }
    return self;
}

- (void)initialize {
    [self.contentView addSubview:self.iconImageView];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.iconImageView.frame = self.contentView.bounds;
}

- (void)setEmoticonImage:(NSString *)emoticonImage {
    self.iconImageView.image = [UIImage new];
    if (!emoticonImage) {
        return;
    }
    
    NSString *path = [[NSBundle mainBundle] pathForResource:emoticonImage ofType:@"png"];
    if (path) {
        NSData *data = [NSData dataWithContentsOfFile:path];
        YYImage *image = [YYImage imageWithData:data scale:1.8];
        image.preloadAllAnimatedImageFrames = YES;
        self.iconImageView.image = image;        
    } else {
        UIImage *image = [UIImage imageNamed:emoticonImage];
        if (image) {
            self.iconImageView.image = image; 
        }
    }
}

#pragma mark - 懒加载
- (UIImageView *)iconImageView {
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] init];
        _iconImageView.contentMode = UIViewContentModeCenter;
    }
    return _iconImageView;
}

@end
